
// export function menussss (oldValue,newValue) {

//     let arr = []
//     let dtInfo = ''
//     for (let i = 0; i < oldValue.length; i++) {
//        for (let j = 0; j < newValue.length; j++) {
//             if(oldValue[i].isNo){
//                 arr.push(oldValue[i])
//                 continue ;
//             }
//         //    console.log(oldValue[i].path,"---",newValue[j].path);
//           if(oldValue[i].path == newValue[j].path){
//               if (oldValue[i].children) {
//                 dtInfo = oldValue[i]

//                 dtInfo.children = menu2(oldValue[i].children , newValue[j].child)
//                 dtInfo.meta.title = newValue[j].title
//                 console.log(66, newValue[j], oldValue[i].children)

//                 // oldValue[i].children.meta.uniqueKey = newValue[j].title
//                 // meta: { uniqueKey: 'projectAdmin1' }
//                 arr.push(dtInfo)
//               }else{
//                 arr.push(oldValue[i])
//               }
//           }
//        }
//     }
//     console.log(88, arr)
//     return arr
// }
export function menu(oldValue, newValue) {
  let arr = [];
  let dtInfo = '';
  
  for (let i = 0; i < oldValue.length; i++) {
    if (oldValue[i].isNo) {
      // 给无需处理的路由也添加唯一key
      arr.push({
        ...oldValue[i],
        meta: {
          ...oldValue[i].meta,
          uniqueKey: `${oldValue[i].path}_${i}_no`
        }
      });
      continue;
    }
    
    for (let j = 0; j < newValue.length; j++) {
      if (oldValue[i].path === newValue[j].path) {
        // 复制路由对象避免污染原数据
        const routeCopy = JSON.parse(JSON.stringify(oldValue[i]));
        
        // 处理子路由
        if (routeCopy.children && newValue[j].child) {
          routeCopy.children = routeCopy.children.map((child, childIdx) => {
            // console.log(55555, child)
            // 处理第二级路由
            const secondLevelRoute = {
              ...child,
              meta: {
                ...child.meta,
                // title: newValue[j].child[childIdx]?.title || child.meta?.title,
                title: child.meta.title,
                uniqueKey: `${routeCopy.path}_${child.path}_${i}_${j}_${childIdx}`
              }
            };
            
            // 处理第三级路由
            if (secondLevelRoute.children && newValue[j].child[childIdx]?.child) {
              secondLevelRoute.children = secondLevelRoute.children.map((grandChild, grandChildIdx) => ({
                ...grandChild,
                meta: {
                  ...grandChild.meta,
                  // title: newValue[j].child[childIdx]?.child[grandChildIdx]?.title || grandChild.meta?.title,
                  title: grandChild.meta.title,
                  uniqueKey: `${routeCopy.path}_${child.path}_${grandChild.path}_${i}_${j}_${childIdx}_${grandChildIdx}`
                }
              }));
            }
            
            return secondLevelRoute;
          });
        }
        
        // 添加唯一标识（结合path和索引）
        routeCopy.meta = {
          ...routeCopy.meta,
          title: newValue[j].title,
          uniqueKey: `${routeCopy.path}_${i}_${j}`  // 第一级唯一key
        };
        
        arr.push(routeCopy);
      }
    }
  }
  
  return arr;
}
export function menuzzzz(oldValue, newValue) {
  let arr = [];
  let dtInfo = '';
  
  for (let i = 0; i < oldValue.length; i++) {
    if (oldValue[i].isNo) {
      // 给无需处理的路由也添加唯一key
      arr.push({
        ...oldValue[i],
        meta: {
          ...oldValue[i].meta,
          uniqueKey: `${oldValue[i].path}_${i}_no`
        }
      });
      continue;
    }
    
    for (let j = 0; j < newValue.length; j++) {
      if (oldValue[i].path === newValue[j].path) {
        // console.log(7799, newValue[j])
        // 复制路由对象避免污染原数据
        const routeCopy = JSON.parse(JSON.stringify(oldValue[i]));
        
        // 处理子路由
        if (routeCopy.children && newValue[j].child) {
          routeCopy.children = menu2(routeCopy.children, newValue[j].child);

        //   获取子级title
        //   console.log(989, routeCopy.children[0].path, newValue[j].child)
        //   let Ptitle
        //   newValue[j].child.forEach(ppl => {
        //     if (ppl.path == routeCopy.children[0].path) {
        //         Ptitle = ppl.title
        //     }
        //   });

          // 给子路由也添加唯一key
          routeCopy.children = routeCopy.children.map((child, idx) => 
            ({
            ...child,
            meta: {
              ...child.meta,
              uniqueKey: `${child.path}_${i}_${j}_${idx}`,
            //   title: Ptitle
            }
          }));
        }
        // console.log(877, routeCopy.children)
        // 添加唯一标识（结合path和索引）
        routeCopy.meta = {
          ...routeCopy.meta,
          title: newValue[j].title,
          uniqueKey: `${routeCopy.path}_${i}_${j}`  // 唯一key
        };
        
        // console.log(988, routeCopy)
        arr.push(routeCopy);
      }
    }
  }
  
  return arr;
}


export function menu2(arr1,arr2) {
    if(!arr2.length)return arr1;
    let arr  = []
    for(let i in arr1){
        for(let l in arr2) {
            if (arr1[i].path == arr2[l].path) {
                if (arr1[i].children) {
                    let dtInfo = arr1[i]
                    let newList = arr2[l].child;
                    dtInfo.children = menu2(arr1[i].children ,newList);
                    arr.push(dtInfo)
                }else{
                    arr.push(arr1[i])
                }
            }
        }
    }
    return arr
}